package com.saul.server.business.pc28;

import com.saul.server.business.pc28.entity.Canada28;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;

/**
 * @author 枫伦
 * @DESCRIPTION
 * @create 2021/5/26 10:15 上午
 */
public class Pc28Forecast {
    private static Map<String, String> companyCodeMap = new HashMap<String, String>();

    static {
        companyCodeMap.put("顺丰速运", "SHSD");
        companyCodeMap.put("顺丰速递", "SHSD");
        companyCodeMap.put("中国邮政EMS", "ZGYZEMS");
        companyCodeMap.put("圆通速递", "YTSD");
    }

    public static void main(String[] args) {
        System.out.println(LocalDateTime.now());
        System.out.println(LocalTime.now());
        System.out.println(LocalDate.now());
//        getForecastResult();
        for (Map.Entry<String, String> stringStringEntry : companyCodeMap.entrySet()) {
            System.out.println(stringStringEntry.getKey() + stringStringEntry.getValue());
        }

    }

    public static Map<String, Object> getForecastResult(int range,int times) {
        Integer a29 = 0;//大
        Integer b29 = 0;//双
        Integer c29 = 0;//小
        Integer d29 = 0;//单
        Integer a20 = 0;//大
        Integer b20 = 0;//双
        Integer c20 = 0;//小
        Integer d20 = 0;//单

        Integer first = 0;
        for (int i = 0; i < 29; i++) {
            Integer sumNum = getSumNum(range);
            if (i == 0) {
                first = sumNum;
            }
            //统计前面20次
            if (i >= 0 && i < 20) {
                if (sumNum % 2 == 0) {
                    b20++;
                } else {
                    d20++;
                }
                if (sumNum >= 14) {
                    a20++;
                } else {
                    c20++;
                }
            }
            if (sumNum % 2 == 0) {
                b29++;
            } else {
                d29++;
            }
            if (sumNum >= 14) {
                a29++;
            } else {
                c29++;
            }
        }
        //第一个
        Canada28 type1 = new Canada28();
        type1.setForecastSum(first).setForecastSize(first >= 14 ? "大" : "小").setForecastSingleDouble(first % 2 == 0 ? "双" : "单");
        //29次
        Canada28 type2 = new Canada28();
        type2.setForecastSum(null).setForecastSize(a29 >= c29 ? "大" : "小").setForecastSingleDouble(b29 >= d29 ? "双" : "单");
        //20次
        Canada28 type3 = new Canada28();
        type3.setForecastSum(null).setForecastSize(a20 >= c20 ? "大" : "小").setForecastSingleDouble(b20 >= d20 ? "双" : "单");
        HashMap<String, Object> map = new HashMap<>();
        map.put("type1", type1);
        map.put("type2", type2);
        map.put("type3", type3);

        System.out.print(times + "期：");
//        System.out.println("第一次：" + first);
        System.out.println(a29 + "大 " + c29 + "小 " + b29 + "双 " + d29 + "单");
//        System.out.println("前20次=" + a20 + "大 " + c20 + "小 " + b20 + "双 " + d20 + "单");
        return map;
    }

    private static Integer getSumNum(int range) {
        Integer[] one = {2, 5, 8, 11, 14, 17};
        Integer[] two = {3, 6, 9, 12, 15, 18};
        Integer[] three = {4, 7, 10, 13, 16, 19};
        List<Integer> listone = Arrays.asList(one);
        List<Integer> listtwo = Arrays.asList(two);
        List<Integer> listthree = Arrays.asList(three);

        //不可重复且有序的20个数字
        Set<Integer> dataset = getIntegers(range);
        Integer bai = 0, shi = 0, ge = 0;
        ArrayList<Integer> intList = new ArrayList<>();
        Iterator<Integer> iterator = dataset.iterator();
        while (iterator.hasNext()) {
            intList.add(iterator.next());
        }
        for (int i = 0; i < intList.size(); i++) {
            if (listone.contains(i)) {
                bai += intList.get(i);
            }
            if (listtwo.contains(i)) {
                shi += intList.get(i);
            }
            if (listthree.contains(i)) {
                ge += intList.get(i);
            }
        }
        String firstNum = bai % 10 + "";
        String towNum = shi % 10 + "";
        String threeNum = ge % 10 + "";
        Integer sumnum = 0;
        try {
            sumnum = Integer.valueOf(firstNum) + Integer.valueOf(towNum) + Integer.valueOf(threeNum);
        } catch (Exception e) {
            System.out.println("出错了！！！三个数字：" + firstNum + "+" + towNum + "+" + threeNum + "+" + ge);
        }
        return sumnum;
    }

    private static Set<Integer> getIntegers(int range) {
        Set<Integer> dataset = new LinkedHashSet<>();
        Random random = new Random();
        for (int i = 0; i < 20; i++) {
            int num = random.nextInt(range);
            dataset.add(num);
        }
        if (dataset.size() < 20) {
            for (int i = 0; i < 100000; i++) {
                int num = random.nextInt(100);
                if (dataset.size() == 20) {
                    break;
                }
                dataset.add(num);
            }
        }
        return dataset;
    }

}
